home *** CD-ROM | disk | FTP | other *** search
- // Text.c
- // 09 Jun 1996 12:19:15
-
- #ifndef BACKUP_INCLUDE
- #include "IncludeAll.c"
- #endif
- #include "Backup.h"
- #include "Backup_proto.h"
-
- #define CATCOMP_ARRAY
- #include "BackupStrings.h"
- #undef STRINGARRAY
-
- static ULONG __saveds __asm DateStrHook(register __a0 struct Hook *theHook,
- register __a1 char NextChar,
- register __a2 struct Locale *myLocale);
- static ULONG __saveds __asm ReadDateHook(register __a0 struct Hook *theHook,
- register __a1 struct Locale *myLocale);
-
-
- // aus Backup_Window.c
- extern struct Library *LocaleBase;
- extern struct Library *UtilityBase;
-
-
- static struct Catalog *li_Catalog;
- struct Locale *myLocale;
-
-
- void myOpenLocale(const char *Language)
- {
- if (UtilityBase && LocaleBase)
- {
- li_Catalog = OpenCatalog(NULL, (STRPTR) "backup.catalog",
- OC_BuiltInLanguage, (STRPTR) "deutsch",
- *Language ? OC_Language : TAG_IGNORE, (STRPTR) Language,
- TAG_END );
-
- myLocale = OpenLocale(NULL);
-
- if (NULL == li_Catalog)
- {
- // Catalog kann nicht geƶffnet werden ... warum auch immer
- }
- else if (li_Catalog->cat_Version != VERSION || li_Catalog->cat_Revision != REVISION)
- {
- alarm(GetString(MSG_WRONG_CATALOG_VERSION),
- li_Catalog->cat_Version, li_Catalog->cat_Revision,
- VERSION, REVISION);
-
- CloseCatalog(li_Catalog);
- li_Catalog = NULL;
- }
- }
- }
-
-
- void myCloseLocale(void)
- {
- if (myLocale)
- CloseLocale(myLocale);
- if (li_Catalog)
- CloseCatalog(li_Catalog);
-
- li_Catalog = NULL;
- myLocale = NULL;
- }
-
-
- const char *GetString(long id)
- {
- struct CatCompArrayType *as;
- const char *s = "";
- short k,l;
-
- l = sizeof(CatCompArray) / sizeof(CatCompArray[0]);
- as = CatCompArray;
- for(k=0; k<l; k++, as++)
- {
- if(as->cca_ID == id)
- {
- s = as->cca_Str;
- break;
- }
- }
-
- if (li_Catalog && *s)
- s = GetCatalogStr(li_Catalog, id, (STRPTR) s);
-
- return(s);
- }
-
-
- char GetDecimalPoint(void)
- {
- return (char) (myLocale ? *myLocale->loc_DecimalPoint : '.');
- }
-
-
- static ULONG __saveds __asm DateStrHook(register __a0 struct Hook *theHook,
- register __a1 char NextChar,
- register __a2 struct Locale *myLocale)
- {
- char **p;
-
- p = (char **) &theHook->h_Data;
- *(*p)++ = NextChar;
-
- return 0L;
- }
-
-
- static ULONG __saveds __asm ReadDateHook(register __a0 struct Hook *theHook,
- register __a1 struct Locale *myLocale)
- {
- char c, **p;
-
- p = (char **) &theHook->h_Data;
- c = isspace(**p) ? '\0' : **p;
- (*p)++;
- return (ULONG) c;
- }
-
-
- char *DateString(short Tag, short Monat, short Jahr)
- {
- static char res[80];
- struct DateStamp ds;
- struct Hook myHook;
-
- if (myLocale)
- {
- ds.ds_Days = PackDate(Tag, Monat, Jahr);
- ds.ds_Minute = 0l;
- ds.ds_Tick = 0l;
-
- myHook.h_Entry = (unsigned long (*)()) DateStrHook;
- myHook.h_Data = res;
-
- FormatDate(myLocale, myLocale->loc_ShortDateFormat, &ds, &myHook);
- }
- else
- {
- sprintf(res, "%2d.%02d.%02d", Tag, Monat, Jahr);
- }
-
- return res;
- }
-
-
- char *TimeString(short Stunde, short Minute, short Sekunde)
- {
- static char res[80];
- struct DateStamp ds;
- struct Hook myHook;
-
- if (myLocale)
- {
- ds.ds_Days = 0;
- ds.ds_Minute = Stunde * 60 + Minute;
- ds.ds_Tick = Sekunde * TICKS_PER_SECOND;
-
- myHook.h_Entry = (unsigned long (*)()) DateStrHook;
- myHook.h_Data = res;
-
- FormatDate(myLocale, myLocale->loc_ShortTimeFormat, &ds, &myHook);
- }
- else
- {
- sprintf(res, "%2d:%02d:%02d", Stunde, Minute, Sekunde);
- }
-
- return res;
- }
-
-
- // Datum aus String lesen und in Tagesnummer (long, ab 1.1.1978) umwandeln
- // liefert 0 bei Fehler im Datum
- long ReadDate(const char *str)
- {
- const char *origStr;
- long tagnr;
- short Tag, Monat, Jahr;
-
- ASSERT_VALID(str);
- if (myLocale)
- {
- struct DateStamp ds;
- struct Hook myHook;
-
- myHook.h_Entry = (unsigned long (*)()) ReadDateHook;
- myHook.h_Data = (char *) str;
-
- if (ParseDate(myLocale, &ds, myLocale->loc_ShortDateFormat, &myHook))
- tagnr = ds.ds_Days;
- else
- tagnr = ~0L;
- }
- else
- {
- origStr = str;
-
- Tag = myatoi(&str, 2); // Tag holen
-
- while (*str && !isdigit(*str))
- str++;
- Monat = myatoi(&str, 2); // Monat holen
-
- while (*str && !isdigit(*str))
- str++;
- Jahr = myatoi(&str, 4); // Jahr holen
-
- tagnr = PackDate(Tag, Monat, Jahr);
- }
-
- if (tagnr == ~0l)
- {
- alarm(GetString(MSG_INVALID_DATE), origStr);
- tagnr = 0;
- }
-
- return tagnr;
- }
-
- // toupper() und tolower() nicht mehr ersetzen, damit kein endloser Aufruf
- #undef toupper
- #undef tolower
-
- UBYTE mytoupper(unsigned long c)
- {
- return (UBYTE) (UtilityBase ? ToUpper(c) : toupper(c));
- }
-
- UBYTE mytolower(unsigned long c)
- {
- return (UBYTE) (UtilityBase ? ToLower(c) : tolower(c));
- }
-
-
- #undef stricmp
- #undef strnicmp
-
- LONG mystricmp(const char *string1, const char *string2 )
- {
- ASSERT_VALID(string1);
- ASSERT_VALID(string2);
-
- return UtilityBase ? Stricmp((STRPTR) string1, (STRPTR) string2) :
- stricmp(string1, string2);
- }
-
-
- LONG mystrnicmp(const char *string1, const char *string2, long length )
- {
- ASSERT_VALID(string1);
- ASSERT_VALID(string2);
-
- return UtilityBase ? Strnicmp((STRPTR) string1, (STRPTR) string2, length)
- : strnicmp(string1, string2, length);
- }
-
-
- void myFormatString(char *Buffer, const char *Format, ...)
- {
- va_list Args;
-
- va_start(Args, Format);
-
- if (LocaleBase && LocaleBase->lib_Version>=38 && myLocale)
- {
- struct Hook myHook;
-
- myHook.h_Entry = (unsigned long (*)()) DateStrHook;
- myHook.h_Data = Buffer;
-
- FormatString(myLocale, (STRPTR) Format, Args, &myHook);
- }
- else
- {
- // hier werden noch die %lU und %lD Formatanweisungen in Kleinbuchstaben umgesetzt,
- // da sie von sprintf nicht erkannt werden.
- char *FormatCopy;
-
- FormatCopy = strdup(Format);
- if (FormatCopy)
- {
- char *p;
-
- p = strstr(Format, "%lU");
- if (p)
- p[2] = 'u';
-
- p = strstr(Format, "%lD");
- if (p)
- p[2] = 'd';
-
- vsprintf(Buffer, Format, Args);
- free(FormatCopy);
- }
- }
-
- va_end(Args);
- }
-
-